using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MainGame
{
    using XGameLibrary.Controls;
    using XGameLibrary.Input;
    using XGameLibrary.ScreenManager;
    using XGameLibrary.SpriteClasses;

    using GameScreens;

    public class Game1 : Game
    {
        private const int ScreenWidth = 1280;
        private const int ScreenHeight = 720;

        public readonly Rectangle ScreenRectangle;

        GraphicsDeviceManager graphics;
        public SpriteBatch SpriteBatch;

        //
        GameStateManager stateManager;
        public TitleScreen TitleScreen;
        public StartMenuScreen StartMenuScreen;
        public GamePlayScreen GamePlayScreen;
        public CharacterGeneratorScreen CharacterGeneratorScreen;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = Game1.ScreenWidth;
            graphics.PreferredBackBufferHeight = Game1.ScreenHeight;

            this.Window.Title = "2SR Adventures";

            this.ScreenRectangle = new Rectangle(
                0,
                0,
                Game1.ScreenWidth,
                Game1.ScreenHeight);

            Content.RootDirectory = "Content";

            Control.Press = Content.Load<SoundEffect>(@"Sounds\Menu\Press");
            Control.Select = Content.Load<SoundEffect>(@"Sounds\Menu\Select");
            AnimatedSprite.WalkingOnGrass = Content.Load<SoundEffect>(@"Sounds\footsteps_forest_01s");
            AnimatedSprite.WalkingOnRock = Content.Load<SoundEffect>(@"Sounds\footstep_rock2");
            AnimatedSprite.WalkingOnWood = Content.Load<SoundEffect>(@"Sounds\footstep_wood");

            Components.Add(new InputHandler(this));

            //
            this.stateManager = new GameStateManager(this);
            Components.Add(stateManager);

            TitleScreen = new TitleScreen(this, this.stateManager);
            StartMenuScreen = new StartMenuScreen(this, this.stateManager);
            GamePlayScreen = new GamePlayScreen(this, this.stateManager);
            CharacterGeneratorScreen = new CharacterGeneratorScreen(this, this.stateManager);

            stateManager.ChangeState(this.TitleScreen);
        }

        protected override void Initialize()
        {

            base.Initialize();
        }

        protected override void LoadContent()
        {
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            QuestionBox.Tinter = Content.Load<Texture2D>(@"Images\Backgrounds\transp");
            AnimatedSprite.StaminaBar = Content.Load<Texture2D>(@"GUI\bar");
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            this.SpriteBatch.Begin();

            this.SpriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
